﻿<UserControl x:Class="eNursePHR.userInterfaceLayer.BloodPressureControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dc="clr-namespace:Microsoft.Samples.KMoore.WPFSamples.DateControls;assembly=J832.Wpf.BagOTricksLib"
    xmlns:ac="clr-namespace:AC.AvalonControlsLibrary.Controls;assembly=AvalonControlsLibrary"
    xmlns:ui="clr-namespace:eNursePHR.userInterfaceLayer"

    >
    <UserControl.Resources>
        <ui:RoundSliderConverter x:Key="RoundSliderConverter" />

        <SolidColorBrush x:Key="colorSystolic" Color="Magenta" />
        <SolidColorBrush x:Key="colorDiastolic" Color="DarkBlue" />
        <SolidColorBrush x:Key="colorPulse" Color="Red" />
        <SolidColorBrush x:Key="colorHighSBP" Color="Black" />
        <SolidColorBrush x:Key="colorHighDBP" Color="Black" />


    </UserControl.Resources>
        <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.7*" />
            <ColumnDefinition Width="1"/>
            <ColumnDefinition Width="0.3*"/>
        </Grid.ColumnDefinitions>
        <!--<Grid.RowDefinitions>
            <RowDefinition Height="250" />
            <RowDefinition Height="150" />
            <RowDefinition Height="150"/>
           
        </Grid.RowDefinitions>-->

        <StackPanel Grid.Column="0" Grid.Row="0">
            <ListView x:Name="lvBP"  HorizontalAlignment="Left" >

                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="130"
        DisplayMemberBinding="{Binding Time}"
        Header="Time" />

                        <GridViewColumn Width="50" 
        DisplayMemberBinding="{Binding SystolicBP}"
        Header="Systolic"  />
                        <GridViewColumn Width="50"
        DisplayMemberBinding="{Binding DiastolicBP}"
        Header="Diastolic" />
                        <GridViewColumn Width="50"
        DisplayMemberBinding="{Binding Pulse}"
        Header="Pulse" />

                        <GridViewColumn  
        DisplayMemberBinding="{Binding Comment}"
        Header="Comment" />
                    </GridView>
                </ListView.View>

            </ListView>

            <FlowDocumentReader x:Name="frBloodpressure" Grid.Column="0" Grid.Row="0" Margin="5" Height="600">
                <FlowDocumentReader.Document>
                    <FlowDocument>
                        <Paragraph>
                            <Figure Width="0.5Page">
                                <BlockUIContainer>
                                    <Image  x:Name="img" Margin="5" />

                                </BlockUIContainer>
                            </Figure>
                        </Paragraph>
                    </FlowDocument>
                </FlowDocumentReader.Document>
            </FlowDocumentReader>

        </StackPanel>

        <GridSplitter Grid.Column="1" Grid.Row="0" Width="1" Background="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

        <StackPanel Grid.Column="2" Grid.Row="0"  Background="{StaticResource BlueTheme}" Margin="5" >
            <Expander Header="Average" IsExpanded="True">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="70" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Image Grid.Column="0" Grid.Row="0" x:Name="imgSystolicAverage" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center"  />
                    <Image Grid.Column="1" Grid.Row="0" x:Name="imgDiastolicAverage" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center"   />
                    <Image Grid.Column="2" Grid.Row="0"  x:Name="imgPulseAverage" Margin="5"  VerticalAlignment="Center"  HorizontalAlignment="Center" />

                    <Label Content="Systolic SBP" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    <Label Content="Diastolic DBP" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    <Label Content="Pulse HR" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" />

                </Grid>

            </Expander>



            <Expander Header="Chart" IsExpanded="True">
                <!--<StackPanel>
                            <Image  x:Name="img" Margin="5" />

                        </StackPanel>-->

            </Expander>

            <Expander  Header="Time and display options" IsExpanded="False">
                <StackPanel Margin="5">


                    <GroupBox Header="Display options" Padding="5" x:Name="gbDisplayOptions">
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                            <CheckBox x:Name="cbShowSystolicBP"  Content="Systolic SBP" IsChecked="{Binding Path=ShowSystolicBP, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="cbDisplayOptionsChanged_Click"  />
                            <CheckBox x:Name="cbShowDisastolicBP" Margin="5,0,0,0" Content="Diastolic DBP" IsChecked="{Binding Path=ShowDiastolicBP, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="cbDisplayOptionsChanged_Click" />
                            <CheckBox x:Name="cbShowPulseHr" Margin="5,0,0,0" Content="Pulse HR" IsChecked="{Binding Path=ShowPulseHR, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="cbDisplayOptionsChanged_Click" />
                            <CheckBox x:Name="cbShowLabels" Margin="5,0,0,0" Content="Show labels" IsChecked="{Binding Path=ShowLabels, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="cbDisplayOptionsChanged_Click" />

                        </StackPanel>

                    </GroupBox>
                </StackPanel>
            </Expander>




            <GroupBox Grid.Row="2" Header="New measurement" Margin="5">
                <Grid  Margin="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="70" />
                        <ColumnDefinition Width="34.684" />
                        <ColumnDefinition Width="251" />
                        <ColumnDefinition Width="37.909*" />
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="35"  />
                        <RowDefinition Height="35"/>
                        <RowDefinition Height="35"/>
                        <RowDefinition Height="50"/>
                        <RowDefinition Height="35"/>
                        <RowDefinition Height="35"/>
                        <RowDefinition Height="35"/>

                    </Grid.RowDefinitions>


                    <Label Grid.Row="0" Grid.Column="0" FontWeight="UltraBold" Foreground="{StaticResource colorSystolic}"
                       Content="Systolic" VerticalAlignment="Center"
                       ToolTip="Systolic blood pressure (mmHg) SBP" HorizontalAlignment="Right"  />

                    <TextBox Grid.Row="0" Grid.Column="1" IsReadOnly="True"  BorderThickness="0" Foreground="{StaticResource colorSystolic}" x:Name="tbSystolicBP" VerticalAlignment="Center"
                         Text="{Binding ElementName=sliderSystolic, Path=Value, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource RoundSliderConverter}}" 
                         HorizontalAlignment="Right">
                        <TextBox.Style>


                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=cbSystolicBP, Path=IsChecked, UpdateSourceTrigger=PropertyChanged}" Value="False">
                                        <Setter Property="TextBox.Visibility"  Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>

                            </Style>

                        </TextBox.Style>

                    </TextBox>

                    <Slider Grid.Row="0" Grid.Column="2" x:Name="sliderSystolic" Minimum="0" Maximum="250" VerticalAlignment="Center"
                AutoToolTipPlacement="BottomRight" IsEnabled="{Binding ElementName=cbSystolicBP, Path=IsChecked, UpdateSourceTrigger=PropertyChanged}"
                Value="120"
                ToolTip="Systolic blood pressure measurement" TickFrequency="20"
                TickPlacement="BottomRight" LargeChange="5"
                 ValueChanged="sliderSystolic_ValueChanged" />

                    <!--<Rectangle Width="50" 
                           Height="{Binding ElementName=sliderSystolic, Path=Value, UpdateSourceTrigger=PropertyChanged}"
                           Fill="{StaticResource colorSystolic}"
                               VerticalAlignment="Bottom"
                           >

                        <Rectangle.RenderTransform>
                            <ScaleTransform ScaleY="0.5" />

                        </Rectangle.RenderTransform>


                    </Rectangle>-->

                    <CheckBox Grid.Row="0" Grid.Column="3"   
                      VerticalAlignment="Center" 
                      x:Name="cbSystolicBP" 
                      IsChecked="True" 
                      ToolTip="Check if reading is valid"
                      HorizontalAlignment="Center" />

                    <Label Grid.Row="1" Grid.Column="0" FontWeight="UltraBold" Foreground="{StaticResource colorDiastolic}" 
                       Content="Diastolic" VerticalAlignment="Center"
                       ToolTip="Diastolic blood pressure (mmHg) DBP" HorizontalAlignment="Right" />

                    <TextBox IsReadOnly="True" Grid.Column="1" Grid.Row="1" BorderThickness="0" Foreground="{StaticResource colorDiastolic}" x:Name="tbDiastolicBP" VerticalAlignment="Center" 
                         Text="{Binding ElementName=sliderDiastolic, Path=Value, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource RoundSliderConverter}}"  HorizontalAlignment="Right" >

                        <TextBox.Style>


                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=cbDiastolicBP, Path=IsChecked, UpdateSourceTrigger=PropertyChanged}" Value="False">
                                        <Setter Property="TextBox.Visibility"  Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>

                            </Style>

                        </TextBox.Style>

                    </TextBox>

                    <Slider Grid.Column="2" Grid.Row="1" x:Name="sliderDiastolic" Minimum="0" Maximum="250" 
                AutoToolTipPlacement="BottomRight" VerticalAlignment="Center"
                Value="70" IsEnabled="{Binding ElementName=cbDiastolicBP, Path=IsChecked, UpdateSourceTrigger=PropertyChanged}"
                ToolTip="Diastolic blood pressure measurement" TickFrequency="20"
                TickPlacement="BottomRight" 
                    ValueChanged="sliderDiastolic_ValueChanged"
                 LargeChange="5"   />

                    <!--<Rectangle Width="50" 
                           Height="{Binding ElementName=sliderSystolic, Path=Value, UpdateSourceTrigger=PropertyChanged}"
                           Fill="{StaticResource colorSystolic}"
                               VerticalAlignment="Bottom"
                           >

                        <Rectangle.RenderTransform>
                            <ScaleTransform ScaleY="0.5" />

                        </Rectangle.RenderTransform>


                    </Rectangle>-->


                    <CheckBox Grid.Row="1" Grid.Column="3" 
                      VerticalAlignment="Center" 
                      x:Name="cbDiastolicBP"  
                      IsChecked="True"
                      
                      ToolTip="Check if reading is valid"
                      HorizontalAlignment="Center"
                      />


                    <Label Grid.Row="2" FontWeight="UltraBold" Foreground="{StaticResource colorPulse}" 
                       Content="Pulse" VerticalAlignment="Center"
                       ToolTip="Pulse or heart rate (HR)" HorizontalAlignment="Right"  />

                    <TextBox IsReadOnly="True" Grid.Column="1" Grid.Row="2" BorderThickness="0" x:Name="tbPulseHR" Foreground="{StaticResource colorPulse}"  VerticalAlignment="Center"
                         Text="{Binding ElementName=sliderPulseHR, Path=Value, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource RoundSliderConverter}}"  
                     HorizontalAlignment="Right">
                        <TextBox.Style>


                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=cbPulseHR, Path=IsChecked, UpdateSourceTrigger=PropertyChanged}" Value="False">
                                        <Setter Property="TextBox.Visibility"  Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>

                            </Style>

                        </TextBox.Style>


                    </TextBox>

                    <Slider Grid.Column="2" Grid.Row="2" x:Name="sliderPulseHR" Minimum="0" Maximum="250" 
                AutoToolTipPlacement="BottomRight" VerticalAlignment="Center"
                Value="60" IsEnabled="{Binding ElementName=cbPulseHR, Path=IsChecked, UpdateSourceTrigger=PropertyChanged}"
                ToolTip="Pulse or heart rate (HR)" TickFrequency="20"
                TickPlacement="BottomRight" 
                LargeChange="5"    />

                    <!--<Rectangle Width="50" 
                           Height="{Binding ElementName=sliderSystolic, Path=Value, UpdateSourceTrigger=PropertyChanged}"
                           Fill="{StaticResource colorSystolic}"
                               VerticalAlignment="Bottom"
                           >

                        <Rectangle.RenderTransform>
                            <ScaleTransform ScaleY="0.5" />

                        </Rectangle.RenderTransform>


                    </Rectangle>-->


                    <CheckBox Grid.Row="2" Grid.Column="3" 
                      VerticalAlignment="Center"
                      x:Name="cbPulseHR"
                      IsChecked="True" 
                      ToolTip="Check if reading is valid"
                      HorizontalAlignment="Center" />

                    <Label Grid.Row="3" FontWeight="UltraBold"   
                       Content="Comment" VerticalAlignment="Center"
                       ToolTip="Pulse or heart rate (HR)" HorizontalAlignment="Right" />

                    <TextBox x:Name="tbComment"
                     Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3"
                     TextWrapping="Wrap"
                      />

                    <Label Grid.Row="4" FontWeight="UltraBold"  
                       Content="Date" VerticalAlignment="Center"
                       ToolTip="Date of measurement" HorizontalAlignment="Right" />


                    <dc:DatePicker x:Name="dpDate" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" 
                               HorizontalAlignment="Left" Width="100"  NullValueText="Enter date"
                               VerticalAlignment="Center"/>


                    <Label Grid.Row="5" FontWeight="UltraBold"   
                       Content="Time" VerticalAlignment="Center"
                       ToolTip="Time of measurement" HorizontalAlignment="Right" />


                    <ac:TimePicker x:Name="tpTime" Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2"
                               HorizontalAlignment="Left" Width="100" VerticalAlignment="Center"  />



                    <Button x:Name="btnAddBPReading" Grid.Column="1" Grid.Row="6" ToolTip="Save reading to database" 
                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                        HorizontalAlignment="Stretch"
                        Click="btnAddBPReading_Click"
                        >
                        <Image Source="Images/Save.png" />
                    </Button>

                    <TextBlock Grid.Row="6" Grid.Column="2" x:Name="tbStatusBP" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,0,0,0"  />




                </Grid>


            </GroupBox>
        </StackPanel>


    </Grid>


</UserControl>
